package com.spring.service.util;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.spring.domain.Content;

public class ContentMapper implements ParameterizedRowMapper<Content> {

    public Content mapRow(ResultSet rs, int rowNum) throws SQLException {
    	Content content = new Content();
    	content.setId(rs.getInt("id"));
    	content.setTitolo(rs.getString("titolo"));
    	content.setStrillo(rs.getString("strillo"));
    	content.setDescrizione(rs.getString("descrizione"));
    	content.setStartDate(rs.getDate("startDate"));
    	content.setEndDate(rs.getDate("endDate"));
    	content.setFk_tipo_cont(rs.getInt("fk_tipo_cont"));
    	content.setFk_tipo_skin(rs.getInt("fk_tipo_skin"));
    	content.setInsDate(rs.getDate("insDate"));
    	content.setHasPrivate(rs.getInt("hasPrivate"));
    	content.setHasGallery(rs.getInt("hasGallery"));
    	content.setHasFile(rs.getInt("hasFile"));
    	content.setHasImg(rs.getInt("hasImg"));
    	
        return content;
    }
    
    public static MapSqlParameterSource sqlMap (Content content){
    	return new MapSqlParameterSource()
				.addValue("id", content.getId())
				.addValue("titolo", content.getTitolo())
				.addValue("strillo", content.getStrillo())
				.addValue("descrizione", content.getDescrizione())
				.addValue("startDate", content.getStartDate())
				.addValue("endDate", content.getEndDate())
				.addValue("fk_tipo_cont",content.getFk_tipo_cont())
				.addValue("fk_tipo_skin",content.getFk_tipo_skin())
				.addValue("insDate", content.getInsDate())
				.addValue("hasPrivate", content.getHasPrivate())
				.addValue("hasGallery", content.getHasGallery())
				.addValue("hasFile", content.getHasFile())
				.addValue("hasImg", content.getHasImg());
    	
    }

}